# coding=utf-8
import re
from urllib.request import urlopen
from urllib.parse import quote

'''
<li data-sku="3065679" class="gl-item">
    <div class="gl-i-wrap">
                    <div class="p-img">
                        <a target="_blank" title="家有爱宠狂欢购！3月16日8点-3月22日24点，萌宠品类日大促，领券下单满199减100，满399减200！点击选购" href="//item.jd.com/3065679.html" onclick="searchlog(1,3065679,0,2,'','flagsClk=1614811800')">
                            <img width="220" height="220" class="err-product" data-img="1" src="//img14.360buyimg.com/n7/jfs/t3829/91/1290499699/81895/4185df72/582ab9ceNac3c7a08.jpg">
                        </a>
                        <div data-catid="7002" data-jq="1" data-dq="1" data-venid="1000001638" data-done="1"></div>
                    </div>
                    <div class="p-price">
<strong class="J_3065679" data-price="519.00" data-done="1"><em>￥</em><i>519.00</i></strong>                    </div>
                    <div class="p-name p-name-type-2">
                        <a target="_blank" title="家有爱宠狂欢购！3月16日8点-3月22日24点，萌宠品类日大促，领券下单满199减100，满399减200！点击选购" href="//item.jd.com/3065679.html" onclick="searchlog(1,3065679,0,1,'','flagsClk=1614811800')">
                            <em>【京东超市】伯纳天纯（Pure&amp;Natural）宠物<font class="skcolor_ljg">狗粮</font>中大型幼犬强化免疫<font class="skcolor_ljg">狗粮</font>15kg</em>
                            <i class="promo-words" id="J_AD_3065679">家有爱宠狂欢购！3月16日8点-3月22日24点，萌宠品类日大促，领券下单满199减100，满399减200！点击选购</i>
                        </a>
                    </div>
        </div>
</li>
'''
# title url img price
keyword = "狗粮"
url = "https://search.jd.com/Search?keyword={0}&enc=utf-8".format(quote(keyword))
html = urlopen(url).read().decode('utf-8')
regex = re.compile(r'<li data-sku=".*" class="gl-item">[\s\S]*?</li>')
patt = re.findall(regex, html)
title_regex = re.compile(r'<em>(.*)</em>')

for i in patt:
    print(re.findall(title_regex, i)[1])




